/*snapInSemitary 2112SnapIn

 A SnapIn that hosts deleted snapIns and the user may resurrect them.

*/

/*
  Create your own !UNIQUE! Namespace by using the JAVA convention of
  reversing your domain name or get a key from 2112Portals, or generate a GUID
  The Problem with domains are:
  1. You could not use domains starting with numbers (like ours 2112Portals.com)
     Since JS does not eval variable starting with numbers.
     So you could circumvent it by adding an underscore.
  2. Well - for every dot-separated string an object would be created.
     So on large Portals with many snapIns this may cause some performance
     issues on the clients.
  3. My recommendation: 
     Use a single unique ID i.e. turn the dots in your Domain Name 
     into myDomain_de/myDomain_net.
*/



/*
NS2112.loadCSS('/yui/build/treeview/assets/treeview-menu.css') ;
NS2112.loadCSS('/yui/assets/yui.css') ;
NS2112.loadCSS('/yui/build/fonts/fonts-min.css');
NS2112.loadCSS('/yui/build/treeview/assets/skins/sam/treeview.css');
*/

NS2112.namespace("GARBAGE_COLLECTOR") ;
NS2112.GARBAGE_COLLECTOR.m_rDeadSnaps = new Object() ;

NS2112.GARBAGE_COLLECTOR.resurrect = function(strSnapInName)
{
  //alert('Resurrecting ' + strSnapInName) ; 
  NS2112.portalMan.getMasterControl().recycle(NS2112.GARBAGE_COLLECTOR.m_rDeadSnaps[strSnapInName]) ;

}

NS2112.GARBAGE_COLLECTOR.garbageCollect = function(theSnap)
{
    //alert('GarbageCollecting: ' + theSnap.Name) ;
    NS2112.GARBAGE_COLLECTOR.m_rDeadSnaps[theSnap.Name] = theSnap;
}

NS2112.namespace("INTRINSICS") ;

   //test = function(a,b,c) {alert('click');}
/*Node definition to instantiate and hang into our tree (and to search for)*/
function Node12(iID, myLabel) 
{
   this.label = myLabel ; 
   this.myID = iID ;
}


NS2112.INTRINSICS.snapSemitary = function(el, userConfig)
{  
   this.constructor.superclass.constructor.call(this, el, userConfig);
   this.Title = "Semitary" ;
   this.Name = 'Semitary';
   this.Width = 200 ;
   this.Height = 150 ;
   this.CanClose = false ;
   //The load callback - load your stuff here
   
   var m_TreeView = null ;
   var ROOT = null ;

   
   
   


   this.onSnapUnload = function(o, theSnap) //theSnap is an array here
   {
      //alert(theSnap[0].Name + ' unloaded!') ;
      var myData = new Node12(theSnap[0].Name, theSnap[0].Title) ;
      var theNode = new YAHOO.widget.TextNode(myData, ROOT, true);
      theNode.href =  'javascript:NS2112.GARBAGE_COLLECTOR.resurrect(' + '\'' + theSnap[0].Name + '\')';
           
      m_TreeView.expandAll ( );
      m_TreeView.draw();
      m_TreeView.expandAll ( );
      theNode.parent.refresh() ;
      NS2112.GARBAGE_COLLECTOR.garbageCollect (theSnap[0]) ;
   }

   this.onSnapRecycle = function(o, theSnap)
   {
      var theNode = m_TreeView.getNodeByProperty('myID', theSnap[0].Name) ;
      //alert(theNode.label + '/' + theSnap[0].Name) ;
      if(theNode)
         m_TreeView.removeNode(theNode, true) ;
   }


   this.load = function(myDiv)
   {  
     
      var myContent =  "<b>snapIn semitary!</b>" ;      
     
      NS2112.portalMan.getMasterControl().onSnapInUnload.subscribe(this.onSnapUnload) ; 
      NS2112.portalMan.getMasterControl().onSnapInRecycle.subscribe(this.onSnapRecycle) ;     
      m_TreeView = new YAHOO.widget.TreeView(myDiv.id);     
      ROOT = new YAHOO.widget.TextNode('Resurrectables', m_TreeView.getRoot(), false);       
      m_TreeView.draw();
      
      return myDiv;
     
   }

   this.unload = function()
   {
      
   }
   //remember? - u need a unique name.     
}

NS2112.extend(NS2112.INTRINSICS.snapSemitary, NS2112.snapIn12);

var rSnapSemitaryDepend = new Array() ;
rSnapSemitaryDepend.push('treeview') ;
NS2112.registerSnapIn(new NS2112.INTRINSICS.snapSemitary(), "com._2112_.snapSemitary", rSnapSemitaryDepend) ;   












